// pages/majorDetail/majorDetail.js
var request = require("../../utils/request.js");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    indicatorDots: false,
    autoplay: false,
    interval: 3000,
    duration: 1000,
    circular: true,
    isclick: false,
    istap: false,
    id: '',
    school_id:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log(options)
    that.setData({
      id: options.id,
      school_id:options.uid
    })
    wx.setNavigationBarTitle({
      title: options.tit,
    })
    that.getData();

  },
  // 获取专业信息
  getData: function () {
    var that = this;
    var url = request.dataUrl + '/api/index/details';
    var params = {
      id: that.data.id,
      status: 2
    }
    request.requestLoading(url, params, '正在加载数据', function (res) {
      console.log(res)
      if (res.code == 0) {
        that.setData({
          list: res.msg
        })
      } else {
        wx.showLoading({
          title: '数据加载中...',
        })
      }

    }, function (res) {
      wx.showToast({
        title: '加载数据失败',
      })
    })
  },
  //获取学校或专业图集
  getPhotos: function () {
    var that = this;
    var url = request.dataUrl + '/api/index/img_list';
    var params = {
      school_id: that.data.school_id,
      pro_id:that.data.id
    }
    request.requestLoading(url, params, '正在加载数据', function (res) {
      console.log(res)
      if (res.code == 0) {
        that.setData({
          img_lis: res.msg,
        })
      } else {
        wx.showToast({
          title: '未加载到数据',
          image:'../../image/fail.png',
          duration:1500
        })       
      }

    }, function (res) {
      wx.showToast({
        title: '加载数据失败',
      })
    })
  },

  // 获取报名信息
  getInfomation: function () {
    var that = this;
    var url = request.dataUrl + '/api/index/get_sign_info';
    console.log(that.data.id);
    var params = {
      session3rd: wx.getStorageSync('session3rd'),
      pro_id: that.data.id
    }
    request.requestLoading(url, params, '正在加载数据', function (res) {
      console.log(res)
      if (res.code == 0) {
        if (res.msg.user_name == "" || res.msg.user_number==""){
          wx.showToast({
            title: '请完善个人信息',
            image:'../../image/fail.png',
            duration:1500,
            success: function () {
              setTimeout(function () {
                wx.navigateTo({
                  url: '../personInfo/personInfo',
                })
              }, 2000)
            }
          })
          that.setData({
            isclick: false
          })
        }else{
          that.setData({
            getinfo: res.msg,
            school_id: res.msg.school_id,
            isclick:true
          })
        }
      
      } else {
        wx.showLoading({
          title: '数据加载中...',
        })
      }

    }, function (res) {
      wx.showToast({
        title: '加载数据失败',
      })
    })
  },
  // 我要报名
  signup(e) {
    var that = this;
    that.getInfomation();
   
  },
  // 蒙版及个人信息
  applyInfo(e) {
    var that = this;
    that.setData({
      isclick: false
    })
  },
  //提交个人专业信息
  formSubmit(e) {
    var that=this;
    console.log(e)
    wx.request({
      url: request.dataUrl + '/api/index/insert_sign',
      data:{
        session3rd:wx.getStorageSync('session3rd'),
        school_id: that.data.school_id,
        pro_id:that.data.id,
        wechat_number: e.detail.value.wxNum
      } ,
      method: 'POST', 
      success: function(res) {
        console.log(res)
        if(res.data.code==0){
          wx.showToast({
            title: res.data.msg,
            image:'../../image/success.png',
            duration:1500,
            success:function(){
              setTimeout(function(){
                wx.navigateBack()
              },2000)
            }
          })
        }else{
          wx.showToast({
            title: res.data.msg,
            image: '../../image/fail.png',
            duration: 1500          
          })
        }
      }
    })

  },
  // 查看图集
  checkImg(e) {
    var that = this;
    that.setData({
      istap: true
    })
    that.getPhotos();
  },
  // 隐藏图集
  bannerImg(e) {
    var that = this;
    that.setData({
      istap: false
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})